package dao

import javax.inject.Inject

import models.Tables._
import play.api.db.slick.{DatabaseConfigProvider, HasDatabaseConfigProvider}
import slick.jdbc.JdbcProfile

import scala.concurrent.Future
import scala.concurrent.ExecutionContext.Implicits.global


class GenotypeDao @Inject()(protected val dbConfigProvider: DatabaseConfigProvider) extends
  HasDatabaseConfigProvider[JdbcProfile] {

  import profile.api._

  def deleteAll: Future[Unit] = db.run(Genotype.delete).map(_ => ())

  def insertAll(rows: Seq[GenotypeRow]): Future[Unit] = {
    db.run(Genotype ++= rows).map(_ => ())
  }

  def selectBySampleNames(sampleNames: Seq[String]): Future[Seq[GenotypeRow]] = db.run(Genotype.filter(_
    .samplename.inSetBind(sampleNames)).result)

  def selectAll: Future[Seq[GenotypeRow]] = db.run(Genotype.take(300000).result)

  def selectAllSampleNames: Future[Seq[String]] = db.run(Genotype.map(_.samplename).distinct.result)

}
